package com.eveinfo.display;

import java.util.Collection;

import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.widget.TextView;

import com.eveinfo.EveInfo;
import com.eveinfo.R;
import com.eveinfo.api.utils.skilllist.ApiRequirement;
import com.eveinfo.api.utils.skilllist.ApiSkill;
import com.eveinfo.api.utils.skilllist.ApiSkills;
import com.eveinfo.tools.Tools;

public class SkillView extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);

		setContentView(R.layout.skill);

		TextView title = (TextView) findViewById(R.id.TVSkillTitle);
		TextView sousTitle = (TextView) findViewById(R.id.TVSkillSousTitle);
		TextView attri = (TextView) findViewById(R.id.TVSkillAttri);
		TextView detail = (TextView) findViewById(R.id.TVSkillDetail);
		TextView required = (TextView) findViewById(R.id.TVSkillRequired);
		TextView next = (TextView) findViewById(R.id.TVSkillNext);

		int typeID = getIntent().getIntExtra("typeID", -1);
		if (typeID == -1){
			//TODO display error message
			return;
		}
		
		ApiSkills allSkill = EveInfo.getData().getSkills();
		ApiSkill skill = allSkill.getSkill(typeID);
		if(skill == null){
			//TODO display error message
			return;
		}
		title.setText(skill.getTypeName());
		sousTitle.setText(allSkill.getGroupName(skill.getGroupID()) + " - Rank " + skill.getRank());
		attri.setText("Primary: " + skill.getPrimaryAttribute() + "\nSecondary: " + skill.getSecondaryAttribute());
		detail.setText(skill.getDescription());

		Collection<ApiRequirement> requiredSkills = skill.getRequiredSkills();
		StringBuilder sb = new StringBuilder();
		sb.append("Required skills :\n");
		for (ApiRequirement requirement : requiredSkills) {
			sb.append("  " + allSkill.getSkillName(requirement.getTypeID()) + " Lvl " + requirement.getSkillLevel()
					+ "\n");
		}
		if (requiredSkills.size() != 0)
			required.setText(sb.toString());

		int characterID = getIntent().getIntExtra("characterID", -1);
		if (characterID != -1) {
			sb.setLength(0);
			sb.append("Lvl I: " + Tools.convertMinutesToTime(Tools.getTimeToLevel(characterID, allSkill, skill, 1, true))
					+ "\n");
			sb.append("Lvl II: " + Tools.convertMinutesToTime(Tools.getTimeToLevel(characterID, allSkill, skill, 2, true))
					+ "\n");
			sb.append("Lvl III: " + Tools.convertMinutesToTime(Tools.getTimeToLevel(characterID, allSkill, skill, 3, true))
					+ "\n");
			sb.append("Lvl IV: " + Tools.convertMinutesToTime(Tools.getTimeToLevel(characterID, allSkill, skill, 4, true))
					+ "\n");
			sb.append("Lvl V: " + Tools.convertMinutesToTime(Tools.getTimeToLevel(characterID, allSkill, skill, 5, true)));
			next.setText(sb.toString());
		}
	}
}
